package io.starteos.wallet.utils.eos.bean;


import com.google.gson.annotations.Expose;

import io.starteos.wallet.utils.eos.crypto.util.HexUtils;
import io.starteos.wallet.utils.eos.data.remote.model.types.EosByteWriter;
import io.starteos.wallet.utils.eos.data.remote.model.types.EosType;
import io.starteos.wallet.utils.eos.data.remote.model.types.TypeAccountName;
import io.starteos.wallet.utils.eos.data.remote.model.types.TypeAsset;

/**
 * Created by haichecker on 18-6-21.
 */

public class EosDelegatebw implements EosType.Packer {
    @Expose
    private TypeAccountName from;
    @Expose
    private TypeAccountName receiver;
    @Expose
    private TypeAsset stake_net_quantity;
    @Expose
    private TypeAsset stake_cpu_quantity;
    @Expose
    private int transfer = 0;

    public String getActionName() {
        return "delegatebw";
    }

    public EosDelegatebw(String from, String receiver, String stake_net_quantity, String stake_cpu_quantity) {
        this(new TypeAccountName(from), new TypeAccountName(receiver), new TypeAsset(stake_net_quantity), new TypeAsset(stake_cpu_quantity));
    }

    public EosDelegatebw(TypeAccountName from, TypeAccountName receiver, TypeAsset stake_net_quantity, TypeAsset stake_cpu_quantity) {
        this.from = from;
        this.receiver = receiver;
        this.stake_net_quantity = stake_net_quantity;
        this.stake_cpu_quantity = stake_cpu_quantity;
    }

    @Override
    public void pack(EosType.Writer writer) {
        from.pack(writer);
        receiver.pack(writer);
        stake_net_quantity.pack(writer);
        stake_cpu_quantity.pack(writer);
        writer.putVariableUInt(transfer);
    }

    public String hex() {
        EosType.Writer writer = new EosByteWriter(512);
        pack(writer);
        return HexUtils.toHex(writer.toBytes());
    }
}
